// pages/login/login.js
Page({

    data: {

    },
    go: function () {
        let wxspAppid="wxae95fcf0b3859284";
        let wxspSecret="57351a280666dde135191798398abdee"
        wx.login({
            success(res) {
                if (res.code) {
                    //发起网络请求
                    wx.request({

                        //这里填你自己的appid 和 wxspSecret 
                        url: "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxspAppid + "&secret=" + wxspSecret + "&js_code=" + res.code + "&grant_type=authorization_code",
                        method: "POST",
                        success(res) { //获取成功要执行的动作
                            console.log(res);
                            wx.switchTab({
                                url:'/pages/index/index'
                            })
                            let appid=res.data.openid;
                            wx.setStorage({
                                key: "gowhere-openid",
                                data: appid,
                                success(res) {
                                  console.log(res)
                                }
                              })
                        },
                        fail(data) { //失败要执行的动作 
                        }
                    })
                } else {
                    console.log('登录失败！' + res.errMsg)
                }
            }
        })
    },
    getopenid(){
        wx.getStorage({
            key: "gowhere-openid",
            success(res) {
              console.log(res.data)
            }
          })
    }
})